package com.abel.serviceuser.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.collect.Lists;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {
    /**
     * swagger2配置文件，可配置swagger2的基本内容，比如扫描的包等
     * @return
     */
    @Bean
    public Docket createRestfulApi(){
        return  new Docket(
                DocumentationType.SWAGGER_2
        ).apiInfo(apiInfo()).pathMapping("/")
                .select().apis(RequestHandlerSelectors.basePackage("com.abel.serviceuser.controller"))
                .paths(PathSelectors.any()).build()
                .securitySchemes(security());
    }
    private ApiInfo apiInfo(){
        return  new ApiInfoBuilder().title("用户权限服务")
                .contact(new Contact("abel","http://www.baidu.com","2417337544@qq.com"))
                .version("1.0").description("用户服务").build();
    }
    private List<ApiKey> security() {
        return Lists.newArrayList(
                new ApiKey("spring:session:sessions", "spring:session:sessions", "user")
        );
    }
}
